const util = {
    addClass(ele, cls) {
        if (!ele || !cls) return;

        cls = cls.trim();
        let cur_class = ele.className;

        cls.split(' ').forEach(item => {
            if (!item) return true;

            if (ele.classList) {
                ele.classList.add(item);
            } else {
                cur_class += ' ' + item;
            }
        });

        !ele.classList && (ele.className = cur_class);
    },

    removeClass(ele, cls) {
        if (!ele || !cls) return;

        cls = cls.trim();
        let cur_class = ' ' + ele.className + ' ';
        cls.split(' ').forEach(item => {
            if (!item) return true;

            if (ele.classList) {
                ele.classList.remove(item);
            } else {
                cur_class = cur_class.replace(' ' + item + ' ', '');
            }
        });

        !ele.classList && (ele.className = cur_class.trim());
    },

    getCSS(ele, prop) {
        return window.getComputedStyle(ele, null).getPropertyValue(prop) || '';
    },
	
	
	copy(value) {
		let transfer = document.createElement('textarea');
		transfer.style.position = 'fixed';
		transfer.style.top = 0;
		transfer.style.left = 0;
		transfer.style.opacity = 0;
		transfer.style.zIndex = -10;;
		document.body.appendChild(transfer);
		transfer.value = value;  // 这里表示想要复制的内容
		transfer.focus();
		transfer.select();
		document.execCommand('copy');
		transfer.blur();
		document.body.removeChild(transfer);
	}
};

export default util;